package nk.backtack;

import java.util.Arrays;
import java.util.Map;
import java.util.Scanner;

public class AB33 {


    public static int ans = 0;

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] nums = new int[n];

        for (int i = 0; i < n; i++) {
            nums[i] = scanner.nextInt();
        }
        if (n == 1) {
            System.out.println(1);
            return;
        }
        Arrays.sort(nums);
        int i = 0, j = 1;
        while (i < j && j < n) {
            if (nums[j] - nums[i] <= k) {
                ans = Math.max(ans, j - i + 1);
                j++;
            } else {
                j++;
                i++;
            }
        }
        System.out.println(ans);
    }




}
